package main

import (
	"encoding/json"
	"net/url"
	"io/ioutil"
	"net/http"
	"fmt"
)

type BDAccess_Token struct{
	grant_type string
	client_id string
	client_secret string
}

type AccessToken struct{
	Refresh_token	string	`json:"refresh_token"`
	Expires_in	int64	`json:"expires_in"`
	Scope	string	`json:"scope"`
	Session_key	string	`json:"session_key"`
	Access_token	string	`json:"access_token"`
	Session_secret	string	`json:"session_secret"`
}

var access_token AccessToken

func main(){
	var u url.URL
	u.Scheme = "https"
	u.Host = "aip.baidubce.com"
	u.Path = "oauth/2.0/token"

	q := u.Query()
	q.Set("grant_type", "client_credentials")
	q.Set("client_id", "R1bqnYtB94Zc839VHZ7l5x6s")
	q.Set("client_secret", "3qm2Q4rhTfhSsgL1QXyQETW6ibqVzlg31")

	u.RawQuery = q.Encode()

	//fmt.Println(u.String())

	resp, err := http.Get(u.String())
	if err != nil {
		fmt.Println(err)
	}
	defer resp.Body.Close()

	rbody, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println(err)
	}

	//lsfile := string(rbody)
	//fmt.Println(lsfile)

	err = json.Unmarshal(rbody, &access_token)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(access_token.Access_token)
	fmt.Println(access_token.Expires_in)


}